package com.igeek.yygh.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeek.yygh.model.healthy.Healthy;
import com.igeek.yygh.result.Result;
import com.igeek.yygh.service.HealthyService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-08-22
 */
@RestController
@RequestMapping("/admin/healthy")
@Slf4j
@Api(tags = "健康指数管理")
public class HealthyController {
    @Autowired
    private HealthyService healthyService;
    @GetMapping("/selectpage")
    public Result selectpage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "8") Integer pageSize,
                             Healthy healthy) {

        List<Healthy> getlist = healthyService.getlist(healthy);
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<Healthy> healthyPageInfo = PageInfo.of(getlist);
        return Result.ok(healthyPageInfo);
    }
    /*
    条件查询一个老人
     */
    @GetMapping("/selectDetailPage")
    public Result selectdetailpage(@RequestParam(defaultValue = "1") Integer pageNum,
                                   @RequestParam(defaultValue = "8") Integer pageSize,
                                   @RequestParam(required = false) Integer olderId,
                                   @RequestParam(required = false) String name,
                                   @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")  @RequestParam(required = false) String startTime,
                                   @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")  @RequestParam(required = false) String endTime   ) {


        System.out.println(startTime);
        Page<Healthy> page = new Page<>(pageNum, pageSize);

//        Page<Healthy> page2 = healthyService.lambdaQuery().select(Healthy::getOlderId).eq(Healthy::getOlderId, olderId).page(page);
//       Page<Healthy> page1 = healthyService.query().select("id","older_id","weight","heart","blood","sugar","create_time").eq("older_id", olderId).page(page);
//       healthyService.page();
        IPage<Healthy> healthyIPage = healthyService.selectUserWithDepartment(page, olderId,name,startTime,endTime);
        return Result.ok(healthyIPage);
    }
}
